/**
 * Application Application.java
 */

package CCT220_Aula18_Exercicio04_13106;


import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;


/**
 * </br>******************************
 * </br>Project: CCT220
 * </br>Package: CCT220_Aula18_Exercicio04_13106
 * </br>Class: Application
 * </br>Last Change: 28/10/2011 13:22:10 by marcel
 * </br>Description:
 * </br>******************************</br>
 * 
 * @author marcel
 * @author 13106
 * 
 */
public class Application implements MouseListener, MouseMotionListener {
	private JLabel jlImage;
	private JLabel jlMousePos;
	private JLabel jlMouseClickPos;
	private JPanel jpPrincipal;


	public Application() {

		this.startComponents();
		JFrame jf = new JFrame("Marcel M.Grilo - 13106");
		jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jf.setSize(400, 250);
		jf.add(jpPrincipal);
		jf.setVisible(true);
	}


	/**
	 * </br>******************************
	 * </br>Package: CCT220_Aula18_Exercicio04_13106
	 * </br>Class: Application
	 * </br>Method: startComponents
	 * </br>Last Change: 28/10/2011 14:21:43 by marcel
	 * </br>Description:
	 * </br>******************************</br>
	 * 
	 */
	private void startComponents() {

		String url = System.getProperty("user.dir")
		        + System.getProperty("file.separator") + "src"
		        + System.getProperty("file.separator")
		        + this.getClass().getPackage().getName()
		        + System.getProperty("file.separator") + "imagem"
		        + System.getProperty("file.separator") + "imagem.png";
		System.out.println(url);
		jpPrincipal = new JPanel(new BorderLayout());
		ImageIcon img = new ImageIcon(url);
		jlImage = new JLabel(img);
		jlImage.addMouseListener(this);
		jlImage.addMouseMotionListener(this);
		jlMouseClickPos = new JLabel("Last Clicked Pos: [0,0]");
		jlMousePos = new JLabel("Pos: [0,0]");
		JPanel jpFlow = new JPanel(new FlowLayout());
		jpFlow.add(jlImage);
		jpPrincipal.add(jpFlow, BorderLayout.CENTER);

		JPanel jpGrid = new JPanel(new GridLayout(1, 2));
		jpGrid.add(jlMouseClickPos);
		jpGrid.add(jlMousePos);

		jpPrincipal.add(jpGrid, BorderLayout.SOUTH);
	}


	public static void main(String[] args) {

		new Application();
	}


	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent
	 * )
	 */
	@Override
	public void mouseDragged(MouseEvent e) {

		// TODO Auto-generated method stub

	}


	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * java.awt.event.MouseMotionListener#mouseMoved(java.awt.event.MouseEvent)
	 */
	@Override
	public void mouseMoved(MouseEvent e) {

		jlMousePos.setText("Pos: [" + e.getX() + "," + e.getY() + "]");
	}


	/*
	 * (non-Javadoc)
	 * 
	 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
	 */
	@Override
	public void mouseClicked(MouseEvent e) {

		jlMouseClickPos.setText("Last Clicked Pos: [" + e.getX() + ","
		        + e.getY() + "]");

	}


	/*
	 * (non-Javadoc)
	 * 
	 * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
	 */
	@Override
	public void mousePressed(MouseEvent e) {

		// TODO Auto-generated method stub

	}


	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
	 */
	@Override
	public void mouseReleased(MouseEvent e) {

		jlMouseClickPos.setText("Last Clicked Pos: [" + e.getX() + ","
		        + e.getY() + "]");

	}


	/*
	 * (non-Javadoc)
	 * 
	 * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
	 */
	@Override
	public void mouseEntered(MouseEvent e) {

		// TODO Auto-generated method stub

	}


	/*
	 * (non-Javadoc)
	 * 
	 * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
	 */
	@Override
	public void mouseExited(MouseEvent e) {

		// TODO Auto-generated method stub

	}
}
